import type { Ref } from "vue";
import request from "../request";
import type { BrandList, HomeList, newProductItem } from "@/types/global";

interface HomeListParams {
  pageNum?: number;
  pageSize?: number;
  keyword?: string | Ref<string>;
}

interface HomeListItem {
  pageNum: number;
  pageSize: number;
  totalPage: number;
  total: number;
  list: HomeList[];
}

interface Homeupdata {
  ids: number;
  recommendStatus: number;
}

interface BrandListItem {
  pageNum: number;
  pageSize: number;
  totalPage: number;
  total: number;
  list: BrandList[];
}

interface BrandListParams {
  keyword?: string | Ref<string>;
  pageNum?: number;
  pageSize?: number;
}

export const gitHomeList = (data?: HomeListParams): Promise<HomeListItem> =>
  request.get("/home/brand/list", { params: data });

//   删除品牌  /home/brand/delete
export const branddelete = (ids: number) =>
  request.post("/home/brand/delete", `ids=${ids}`);

// 批量修改推荐品牌状态 /home/brand/update/recommendStatus
export const Homebrandupdate = (data: Homeupdata) =>
  request.post(
    "/home/brand/update/recommendStatus",
    `ids=${data.ids}&recommendStatus=${data.recommendStatus}`
  );

// 根据品牌名称分页获取品牌列表  /brand/lists
export const getBrandList = (data?: BrandListParams): Promise<BrandListItem> =>
  request.get("/brand/list", { params: data });

// 添加品牌 /home/brand/create
export const BrandCreate = (data: BrandList): Promise<any> =>
  request.post("/home/brand/create", [
    { brandId: data.id, brandName: data.name },
  ]);

//人气推荐 /home/recommendProduct/list
export const getrecommendProduct = (data?: any): Promise<any> =>
  request.get("/home/recommendProduct/list", { params: data });

// 首页轮播广告管理

// 分页查询广告 类型 /home/advertise/list

interface advertiseItem {
  pageNum: number;
  pageSize: number;
  totalPage: number;
  total: number;
  list: advertiseList[];
}

interface advertiseList {
  id: number;
  name: string;
  type?: number;
  pic: string;
  startTime: string;
  endTime: string;
  status: number;
  clickCount: number;
  orderCount: number;
  url: string;
  note: string;
  sort: number;
}

interface advertisePromise {
  endTime?: string;
  name?: string;
  pageNum?: number;
  pageSize?: number;
  type?: number;
}
// 分页查询广告
export const getadvertise = (data?: advertisePromise): Promise<advertiseItem> =>
  request.get("/home/advertise/list", { params: data });

// 删除广告 /home/advertise/delete
export const advertisdelete = (ids: number) =>
  request.post("/home/advertise/delete", `ids=${ids}`);

///home/advertise/update/status/{id}  修改上下线状态
interface POSTadvertisePromise {
  id?: number | Ref<number>;
  status?: number;
}
export const AdvertiseUpdate = (data: POSTadvertisePromise) =>
  request.post(
    `/home/advertise/update/status/${data.id}`,
    `status=${data.status}`
  );

// 新品管理  /home/newProduct/list
interface newProductList {
  pageNum?: number;
  pageSize?: number;
  productName?: string;
  recommendStatus?: number;
  keyword?: string | Ref<string>;
}

interface newProductPromise {
  pageNum: number;
  pageSize: number;
  totalPage: number;
  total: number;
  list: newProductItem[];
}

// 查询列表渲染信息
export const getnewProductList = (
  data?: newProductList
): Promise<newProductPromise> =>
  request.get("/home/newProduct/list", { params: data });

// 批量修改状态  /home/newProduct/update/recommendStatus
export const HomenewProductupdate = (data: Homeupdata) =>
  request.post(
    "/home/newProduct/update/recommendStatus",
    `ids=${data.ids}&recommendStatus=${data.recommendStatus}`
  );
// 删除  /home/newProduct/delete
export const newProductdelete = (ids: number) =>
  request.post("/home/newProduct/delete", `ids=${ids}`);

// 人气推荐
interface recommendProductList {
  pageNum?: number;
  pageSize?: number;
  productName?: string;
  recommendStatus?: number;
  keyword?: string | Ref<string>;
}

interface recommendProductPromise {
  pageNum: number;
  pageSize: number;
  totalPage: number;
  total: number;
  list: recommendProductItem[];
}

interface recommendProductItem {
  id: number;
  productId: number;
  productName: string;
  recommendStatus: number;
  sort: number;
}

// /home/recommendProduct/list  分页查询
export const recommendProductList = (
  data?: recommendProductList
): Promise<recommendProductPromise> =>
  request.get("/home/recommendProduct/list", { params: data });

// 切换状态     /home/recommendProduct/update/recommendStatus
export const HomerecommendStatusupdate = (data: Homeupdata) =>
  request.post(
    "/home/recommendProduct/update/recommendStatus",
    `ids=${data.ids}&recommendStatus=${data.recommendStatus}`
  );

// 删除 /home/recommendProduct/delete
export const recommendProductdelete = (ids: number) =>
  request.post("/home/recommendProduct/delete", `ids=${ids}`);

// 专题推荐

interface recommendSubjectList {
  pageNum?: number;
  pageSize?: number;
  productName?: string;
  recommendStatus?: number;
  keyword?: string | Ref<string>;
}

interface recommendSubjectPromise {
  pageNum: number;
  pageSize: number;
  totalPage: number;
  total: number;
  list: recommendSubjectItem[];
}

interface recommendSubjectItem {
  id: number;
  subjectId: number;
  subjectName: string;
  recommendStatus: number;
  sort: number;
}
// 分页查询   /home/recommendSubject/list
export const recommendSubjectList = (
  data?: recommendSubjectList
): Promise<recommendSubjectPromise> =>
  request.get("/home/recommendSubject/list", { params: data });

// 分页删除 /home/recommendSubject/delete
export const recommendSubjectdelete = (ids: number) =>
  request.post("/home/recommendSubject/delete", `ids=${ids}`);

// 分页状态切换
export const HomerecommendSubjectupdate = (data: Homeupdata) =>
  request.post(
    "/home/recommendSubject/update/recommendStatus",
    `ids=${data.ids}&recommendStatus=${data.recommendStatus}`
  );
